package main_form

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
)

// MainSceneConfig 主窗口
type MainSceneConfig struct {
	XMLName    xml.Name `xml:"root"`
	Title      string   `xml:"Title"`
	MainWidth  int      `xml:"MainWidth"`
	MainHeight int      `xml:"MainHeight"`

	Widgets []SceneWidget `xml:"Widget"`
}

func LoadMainScene(filename string) (*MainSceneConfig, error) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, err
	}
	return loadMainSceneConfigFromData(data)
}

func loadMainSceneConfigFromData(data []byte) (*MainSceneConfig, error) {
	var config MainSceneConfig
	err := xml.Unmarshal([]byte(data), &config)
	if err != nil {
		fmt.Println("Error:", err)
		return nil, err
	}
	return &config, nil
}
